<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text" placeholder="enter the name you search"
             v-model.trim="searchName"/>
      <button @click="search">Search</button>
    </div>
  </section>
</template>

<script>
    import {mapActions} from "vuex"
    export default {
        name:"v-search",
        computed:{
          searchName:{
            get(){return this.$store.state.searchName},
            set(val){
              //当组件上的searchName数据改变时 要同步仓库中的数据
              // this.$store.dispatch("searchName",val)
              this.searchNameFn(val)
            }
          }
        },
        methods:{
          /*
            searchNameFn(val){
              this.$store.dispatch("searchName",val)
            },
            searchFn(val){
              this.$store.dispatch("search",val)
            }
          */
          ...mapActions({
            searchNameFn:"searchName",
            searchFn:"search"
          }),

          //拿到用户输入的数据 发送请求 获取对应的用户列表
          search(){
            //转发一个action!!!
            this.searchFn()
          }
        }
    }
</script>

<style scoped>

</style>
